package com.huaxin.hxmoduleworkorder.mapping;

import com.huaxin.hxenum.enums.Unit;
import com.huaxin.hxmoduleworkorder.common.enums.CustomerType;
import com.huaxin.hxmoduleworkorder.common.enums.InspectionTemplateItemCategory;
import com.huaxin.hxmoduleworkorder.common.enums.InspectionTemplateItemEquipmentType;
import com.huaxin.hxmoduleworkorder.common.enums.InspectionTemplateItemType;
import com.huaxin.hxmoduleworkorder.dto.request.InspectionTemplateItemCreateReqDTO;
import com.huaxin.hxmoduleworkorder.dto.request.InspectionTemplateItemUpdateReqDTO;
import com.huaxin.hxmoduleworkorder.models.InspectionTemplateItem;
import org.mapstruct.AfterMapping;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.MappingTarget;

@Mapper(componentModel = "spring")
public interface InspectionTemplateItemMapping {

    @Mapping(target = "category", ignore = true)
    @Mapping(target = "equipmentType", ignore = true)
    @Mapping(target = "customerType", ignore = true)
    @Mapping(target = "unit", ignore = true)
    InspectionTemplateItem toEntity(InspectionTemplateItemCreateReqDTO in);

    @AfterMapping
    default void afterMapping(InspectionTemplateItemCreateReqDTO dto, @MappingTarget InspectionTemplateItem entity) {
        entity.setCategory(InspectionTemplateItemCategory.of(dto.getCategory()));
        entity.setEquipmentType(InspectionTemplateItemEquipmentType.of(dto.getEquipmentType()));
        entity.setCustomerType(CustomerType.of(dto.getCustomerType()));
        entity.setUnit(Unit.of(dto.getUnit()));
    }

    @Mapping(target = "category", ignore = true)
    @Mapping(target = "equipmentType", ignore = true)
    @Mapping(target = "customerType", ignore = true)
    @Mapping(target = "unit", ignore = true)
    void updateEntity(InspectionTemplateItemUpdateReqDTO in, @MappingTarget InspectionTemplateItem entity);

    @AfterMapping
    default void afterMapping(InspectionTemplateItemUpdateReqDTO dto, @MappingTarget InspectionTemplateItem entity) {
        entity.setCategory(InspectionTemplateItemCategory.of(dto.getCategory()));
        entity.setEquipmentType(InspectionTemplateItemEquipmentType.of(dto.getEquipmentType()));
        entity.setCustomerType(CustomerType.of(dto.getCustomerType()));
        entity.setUnit(Unit.of(dto.getUnit()));
    }
}